package com.tiny.handler;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;

import com.jfinal.handler.Handler;
import com.tiny.model.SysLog;
import com.tiny.thread.ThreadSysLog;
import com.tiny.tools.ToolWeb;

public class GlobalHandler extends Handler {
	
	private static Logger log = Logger.getLogger(GlobalHandler.class);
	private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	@Override
	public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
		log.info("设置 web 路径");
		String cxt = ToolWeb.getContextPath(request);
		request.setAttribute("cxt", cxt);
		
		/**log.info("记录日志");
		
		//记录操作日志
		SysLog reqSysLog = new SysLog();

		reqSysLog.set("starttime", sdf.format(new Date()));
		reqSysLog.set("username", request.getHeader("User-Agent"));
		reqSysLog.set("ip", ToolWeb.getIpAddr(request));
		reqSysLog.set("controller", ToolWeb.getRequestURIWithParam(request));
		
		log.info("日志添加到入库队列");
		ThreadSysLog.add(reqSysLog);**/
		
		nextHandler.handle(target, request, response, isHandled);
	}
}
